package com.ljr;

/**
 * @author ljr
 * @version 1.0
 * @description:  设计模式之美28, 查找递增数组中第一个大于等于某个给定值的元素
 * @date 2021/12/28 21:20
 */
public class BinarySearch {

    public int getBinarySearchResult(int[] nums, int value){
        if(nums == null || nums.length == 0) return -1;
        int high = nums.length-1;
        int low = 0;
        while(low < high){
            int mid = low + (high - low >> 1);
            if(nums[mid] >= value){
                high = mid - 1;
            }else{
                low = mid + 1;
            }
        }

        if(nums[low] >= value) return low;
        return -1;
    }

}
